package com.clgk.wechatmall.common.sql;

import java.io.Serializable;

public class Page implements Serializable {
	
	
	private static final long serialVersionUID = -5552772263240378350L;

	private int counts = -1;

	private int pageSize = 10;

	private int totalPage = 1;

	private int curPage = 1;

	private int firstResult = 1;

	private int lastResult = 1;
	private String orderName;
	private String orderType;
	private String orderBy;

	public Page(int counts, int pageSize) {
		this.counts = counts;

		if (counts % pageSize == 0) {
			this.totalPage = (this.counts / this.pageSize);
		} else {
			this.totalPage = (this.counts / this.pageSize + 1);
		}
	}

	public Page() {
	}

	public int getCounts() {
		return this.counts;
	}

	public void setCounts(int counts, int pageSize) {
		this.pageSize = pageSize;

		this.counts = counts;

		if (counts % this.pageSize == 0) {
			this.totalPage = (this.counts / this.pageSize);
		} else {
			this.totalPage = (this.counts / this.pageSize + 1);
		}
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		if (this.totalPage < 1) {
			return 1;
		}
		return this.totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurPage() {
		return this.curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getFirstResult() {
		int temp = this.curPage - 1;
		if (temp <= 0) {
			return 0;
		}
		return this.firstResult = (this.curPage - 1) * this.pageSize;
	}

	public void setFirstResult(int firstResult) {
		this.firstResult = firstResult;
	}

	public int getLastResult() {
		this.lastResult = (this.firstResult + this.pageSize);
		return this.lastResult;
	}

	public void setLastResult(int lastResult) {
		this.lastResult = lastResult;
	}

	public String getOrderName() {
		return this.orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public String getOrderType() {
		return this.orderType;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	public String getOrderBy() {
		if ((getOrderName() == null) || (getOrderName().equals(""))
				|| (getOrderType() == null) || (getOrderType().equals(""))) {
			return "";
		}
		this.orderBy = (" order by " + getOrderName() + " " + getOrderType());

		return this.orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}
}